import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] ages) throws Exception {
        try {
            PropertiesConfiguration configuration = new PropertiesConfiguration("C:\\Users\\zxw\\translation\\proble.properties");
            String test = configuration.getString("test");
            System.out.println(test);
            configuration.save();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }

    public static Optional<String> englishWordSegmentation(String enWord){
        try {
            Pattern compile = Pattern.compile("[a-zA-Z]");
            Pattern capital = Pattern.compile("[A-Z]");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < enWord.length(); i++) {
                String v = String.valueOf(enWord.charAt(i));
                if (!compile.matcher(v).matches()){
                    String substring = sb.substring(sb.length() - 1);
                    if (!StringUtils.isBlank(substring)){
                        sb.append(" ");
                    }
                    continue;
                }
                if (capital.matcher(v).matches()){//capital
                    String substring = sb.substring(sb.length() - 1);
                    if (!StringUtils.isBlank(substring)){
                        sb.append(" ");
                    }
                    sb.append(v);
                }else {
                    sb.append(v);
                }
            }
            return Optional.ofNullable(sb.toString());
        }catch (Exception e){
            e.printStackTrace();
            return Optional.empty();
        }
    }
}
